home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet internetowy / Przegladarki internetowe / Mozilla Seamonkey 1.0.5 pl / seamonkey-1.0.5.pl-PL.win32.installer.exe / XPCOM.XPI / install.js
Encoding:
JavaScript  |  2006-09-10  |  5.6 KB  |  209 lines

  1. // this function verifies disk space in kilobytes
  2. function verifyDiskSpace(dirPath, spaceRequired)
  3. {
  4.   var spaceAvailable;
  5.  
  6.   // Get the available disk space on the given path
  7.   spaceAvailable = fileGetDiskSpaceAvailable(dirPath);
  8.  
  9.   // Convert the available disk space into kilobytes
  10.   spaceAvailable = parseInt(spaceAvailable / 1024);
  11.  
  12.   // do the verification
  13.   if(spaceAvailable < spaceRequired)
  14.   {
  15.     logComment("Insufficient disk space: " + dirPath);
  16.     logComment("  required : " + spaceRequired + " K");
  17.     logComment("  available: " + spaceAvailable + " K");
  18.     return(false);
  19.   }
  20.  
  21.   return(true);
  22. }
  23.  
  24. // this function deletes a file if it exists
  25. function deleteThisFile(dirKey, file)
  26. {
  27.   var fFileToDelete;
  28.  
  29.   fFileToDelete = getFolder(dirKey, file);
  30.   logComment("File to delete: " + fFileToDelete);
  31.   if(File.isFile(fFileToDelete))
  32.   {
  33.     File.remove(fFileToDelete);
  34.     return(true);
  35.   }
  36.   else
  37.     return(false);
  38. }
  39.  
  40. // this function deletes a folder if it exists
  41. function deleteThisFolder(dirKey, folder, recursiveDelete)
  42. {
  43.   var fToDelete;
  44.  
  45.   if(typeof recursiveDelete == "undefined")
  46.     recursiveDelete = true;
  47.  
  48.   fToDelete = getFolder(dirKey, folder);
  49.   logComment("folder to delete: " + fToDelete);
  50.   if(File.isDirectory(fToDelete))
  51.   {
  52.     File.dirRemove(fToDelete, recursiveDelete);
  53.     return(true);
  54.   }
  55.   else
  56.     return(false);
  57. }
  58.  
  59. // OS type detection
  60. // which platform?
  61. function getPlatform()
  62. {
  63.   var platformStr;
  64.   var platformNode;
  65.  
  66.   if('platform' in Install)
  67.   {
  68.     platformStr = new String(Install.platform);
  69.  
  70.     if (!platformStr.search(/^Macintosh/))
  71.       platformNode = 'mac';
  72.     else if (!platformStr.search(/^Win/))
  73.       platformNode = 'win';
  74.     else if (!platformStr.search(/^OS\/2/))
  75.       platformNode = 'win';
  76.     else
  77.       platformNode = 'unix';
  78.   }
  79.   else
  80.   {
  81.     var fOSMac  = getFolder("Mac System");
  82.     var fOSWin  = getFolder("Win System");
  83.  
  84.     logComment("fOSMac: "  + fOSMac);
  85.     logComment("fOSWin: "  + fOSWin);
  86.  
  87.     if(fOSMac != null)
  88.       platformNode = 'mac';
  89.     else if(fOSWin != null)
  90.       platformNode = 'win';
  91.     else
  92.       platformNode = 'unix';
  93.   }
  94.  
  95.   return platformNode;
  96. }
  97.  
  98. function upgradeCleanup()
  99. {
  100.   deleteThisFile("Program",    "zlib.dll");
  101.   deleteThisFile("Program",    "component.reg");
  102.   deleteThisFile("Components", "compreg.dat");
  103.   deleteThisFile("Components", "xpti.dat");
  104.   deleteThisFile("Components", "xptitemp.dat");
  105. }
  106.  
  107. // main
  108. var srDest;
  109. var err;
  110. var szUninstall;
  111. var fProgram;
  112. var fWindowsSystem;
  113. var fileComponentReg;
  114. var fileComponentRegStr;
  115. var fileMsvcrt;
  116. var fileMsvcirt;
  117.  
  118. srDest = 1697;
  119. err    = initInstall("Mozilla XPCOM", "XPCOM", "1.0.5.2006091003"); 
  120. logComment("initInstall: " + err);
  121.  
  122. fProgram  = getFolder("Program");
  123. fWindowsSystem = getFolder("Win System");
  124. logComment("fProgram: " + fProgram);
  125.  
  126. // build the uninstall folder path
  127. szUninstall = fProgram + "Uninstall";
  128.  
  129. // Log component.reg file so it can be deleted by the uninstaller.
  130. // These two files are created after installation is done, thus
  131. // are normally not logged for uninstall.
  132. logComment("Installing: " + fProgram + "component.reg");
  133.  
  134. if(verifyDiskSpace(fProgram, srDest))
  135. {
  136.   setPackageFolder(fProgram);
  137.  
  138.   upgradeCleanup();
  139.   err = addDirectory("",
  140.                      "1.0.5.2006091003",
  141.                      "bin",              // dir name in jar to extract 
  142.                      fProgram,           // Where to put this file (Returned from GetFolder) 
  143.                      "",                 // subdir name to create relative to fProgram
  144.                      true);              // Force Flag 
  145.   logComment("addDirectory() of Program returned: " + err);
  146.  
  147.   if( err == SUCCESS )
  148.   {
  149.     // install msvcrt.dll *only* if it does not exist
  150.     // we don't care if addFile() fails (if the file does not exist in the archive)
  151.     // bacause it will still install
  152.     fileMsvcrt = getFolder(fWindowsSystem, "msvcrt.dll");
  153.     rv         = File.exists(fileMsvcrt);
  154.     logComment("fileExists() returned: " + rv);
  155.     if(rv == false)
  156.     {
  157.       logComment("File not found: " + fileMsvcrt);
  158.       addFile("/Microsoft/Shared/msvcrt.dll",
  159.               "1.0.5.2006091003",
  160.               "msvcrt.dll",         // dir name in jar to extract 
  161.               fWindowsSystem,       // Where to put this file (Returned from getFolder) 
  162.               "",                   // subdir name to create relative to fProgram
  163.               WIN_SHARED_FILE);
  164.       logComment("addFile() of msvcrt.dll returned: " + err);
  165.     }
  166.     else
  167.     {
  168.       logComment("File found: " + fileMsvcrt);
  169.     }
  170.  
  171.     // install msvcirt.dll *only* if it does not exist
  172.     // we don't care if addFile() fails (if the file does not exist in the archive)
  173.     // bacause it will still install
  174.     fileMsvcirt = getFolder(fWindowsSystem, "msvcirt.dll");
  175.     rv          = File.exists(fileMsvcirt);
  176.     logComment("fileExists() returned: " + rv);
  177.     if(rv == false)
  178.     {
  179.       logComment("File not found: " + fileMsvcirt);
  180.       addFile("/Microsoft/Shared/msvcirt.dll",
  181.               "1.0.5.2006091003",
  182.               "msvcirt.dll",        // dir name in jar to extract 
  183.               fWindowsSystem,       // Where to put this file (Returned from getFolder) 
  184.               "",                   // subdir name to create relative to fProgram
  185.               WIN_SHARED_FILE);
  186.       logComment("addFile() of msvcirt.dll returned: " + err);
  187.     }
  188.     else
  189.     {
  190.       logComment("File found: " + fileMsvcirt);
  191.     }
  192.   }
  193.  
  194.   // check return value
  195.   if( err == SUCCESS )
  196.   {
  197.     err = performInstall(); 
  198.     logComment("performInstall() returned: " + err);
  199.   }
  200.   else
  201.     cancelInstall(err);
  202. }
  203. else
  204.   cancelInstall(INSUFFICIENT_DISK_SPACE);
  205.  
  206.  
  207. // end main
  208.  
  209.